package com.smzd.ccms.actions;

import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.smzd.ccms.business.ChannelConfigService;
import com.smzd.ccms.business.ChannelService;
import com.smzd.ccms.domain.Channel;
import com.smzd.ccms.domain.ChannelConfig;
import com.smzd.framework.annotation.Access;
import com.smzd.framework.core.actions.AbstractScopedController;
import com.smzd.framework.core.business.IFGService;
import com.smzd.framework.utils.db.SRPage;

@Controller
@RequestMapping("/channel/{channelId}/channelcfgs")
@Access("TAG_ROLE_CCMS")
public class ChannelConfigController extends AbstractScopedController<ChannelConfig, Channel> {
    @Autowired
    private ChannelConfigService service;

    @Override
    protected IFGService<ChannelConfig> getService() {
        return service;
    }
    @Autowired
    private ChannelService channelService;
    
    @Override
    protected Channel getScope(int scopeId) {
        return channelService.getItemById(scopeId);
    }

    @RequestMapping(value="/add", method=RequestMethod.GET)
    @Override
    public String toAddPage(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        return super.toAddPage(model, scopeId, elem, result);
    }

    @RequestMapping(value="/add", method=RequestMethod.POST)
    @ResponseBody
    @Override
    public String postAddData(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        return super.postAddData(model, scopeId, elem, result);
    }

    @RequestMapping(method=RequestMethod.GET)
    @Override
    public String toListPage(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        return super.toListPage(model, scopeId, elem, result);
    }

    @RequestMapping(value="/list", method=RequestMethod.POST)
    @ResponseBody
    @Override
    public String getListData(Map<String, Object> model,
            @PathVariable("channelId") int scopeId,
            SRPage<Channel, ChannelConfig> page,
            BindingResult result) throws Exception {
        return super.getListData(model, scopeId, page, result);
    }

    @RequestMapping(value="/edit", method=RequestMethod.GET)
    @Override
    public String toEditPage(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        elem = service.getItemById(elem.getId());
        return super.toEditPage(model, scopeId, elem, result);
    }

    @RequestMapping(value="/edit", method=RequestMethod.POST)
    @ResponseBody
    @Override
    public String postEditData(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        return super.postEditData(model, scopeId, elem, result);
    }

    @RequestMapping(value="/remove", method=RequestMethod.POST)
    @ResponseBody
    @Override
    public String postRemoveData(Map<String, Object> model,
            @PathVariable("channelId") int scopeId, ChannelConfig elem,
            BindingResult result) throws Exception {
        return super.postRemoveData(model, scopeId, elem, result);
    }
    
}